package com.zyzy.leftfourdead.adapter.ProductActivityAdapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.zyzy.leftfourdead.R;
import com.zyzy.leftfourdead.bean.PreductBean;
import com.zyzy.leftfourdead.helper.BaseAdapterHelper;

import java.util.List;
import java.util.Map;

/**
 * Created by hqd on 2016/8/24.
 */
public class ProductListViewInstructionAdapter  extends BaseAdapter {

    public Context context = null;
    public  List<PreductBean.InstructionBean> list = null;
    public LayoutInflater inflater = null;

    public ProductListViewInstructionAdapter(Context context,List<PreductBean.InstructionBean> list) {
        this.context = context;
        this.list = list;
        inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    //    刷新list
    public void reloadListView(List<PreductBean.InstructionBean> data, boolean isClear) {
        if (isClear) {
            list.clear();
        }
        list.addAll(data);
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_product_listview_instruction, parent, false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.textView_item_product_listview_instruction_tital.setText(list.get(position).getTitle());
        viewHolder.textView_item_product_listview_instruction_context.setText(list.get(position).getDescription());
        Glide.with(context).load(list.get(position).getImage()).into(viewHolder.imageview_item_product_listview_instruction);
        return convertView;
    }

    class ViewHolder {
        private ImageView imageview_item_product_listview_instruction;
        private TextView textView_item_product_listview_instruction_tital;
        private TextView textView_item_product_listview_instruction_context;

        public ViewHolder(View convertView) {
            imageview_item_product_listview_instruction= (ImageView) convertView.findViewById(R.id.imageview_item_product_listview_instruction);
            textView_item_product_listview_instruction_tital = (TextView) convertView.findViewById(R.id.textView_item_product_listview_instruction_tital);
            textView_item_product_listview_instruction_context = (TextView) convertView.findViewById(R.id.textView_item_product_listview_instruction_context);
        }
    }
}